﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace miSuperEngine
{
    public class Animation
    {
        public Texture2D texture;
        public int speed;
        public int currentFrame;
        public int xFrames, yFrames, totalFrames;
        public int elapsedTime;

        public Animation(Texture2D tex, int xCount, int yCount, int _totalFrames,int _speed)
        {
            texture = tex;
            xFrames = xCount;
            yFrames = yCount;
            totalFrames = _totalFrames;
            speed = _speed;
        }
        public Rectangle getRect()
        {
           Rectangle returnRect;
            returnRect.Width=texture.Width/xFrames;
            returnRect.Height=texture.Height/yFrames;
            returnRect.X=returnRect.Width*(currentFrame%xFrames);
            returnRect.Y = returnRect.Height * (currentFrame / yFrames);
            return returnRect;
        }
        public bool update(GameTime time)
        {
            elapsedTime += time.ElapsedGameTime.Milliseconds;
            if (elapsedTime > speed)
            {
                elapsedTime-=speed;
                currentFrame++;
                if (currentFrame >= totalFrames)
                    currentFrame = 0;
            }
            return false;
        }

        
    }
}
